package com.wurd.repository;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.util.List;

@Repository
public class TestRepository {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private SessionFactory sessionFactory;

    @Autowired
    private HibernateTemplate hibernateTemplate;

    public void test() {
        for (int i = 0; i < 5; i++) {
//            Test test = new Test();
//            test.setName("1");
//            hibernateTemplate.save(test);
            String sql = "from Test where 1=1";
            if (i > 1) {
                sql = sql + " or aa=1";
            }
            Query query = hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(sql);
//            Query query = hibernateTemplate.getSessionFactory().openSession().createQuery(sql);
            List rs = query.list();
            System.out.print("");
        }
    }

}
